package humynn.engine
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.events.Event;

	/**
	 * The Entity class is the base class for all game objects managed
	 * by the engine.
	 */
	public class Entity implements IEventDispatcher
	{
		public var visible:Boolean;
		public var x:Number;
		public var y:Number;
		
		protected var _imageFile:String;
		protected var _animIndex:uint;
		protected var _animFrame:uint;
		
		protected var _dispatcher:EventDispatcher;
		
		/**
		 * Sets the name of the file to use as the graphic that represents
		 * this Entity.
		 * 
		 * @param value The name of the file to use when drawing.
		 */
		public function set imageFile(value:String):void
		{
			_imageFile = value;
		}
		
		/**
		 * Sets the initial values for an entity.
		 */
		public function Entity()
		{
			visible = true;
		}
		
		/**
		 * An empty update function that does nothing. Called each frame.
		 * 
		 * @param input The user input.
		 */
		public function update(input:Input):void
		{
			
		}
		
		/**
		 * A basic draw function, suitable for most uses.
		 * 
		 * @param renderer The renderer to draw to.
		 */
		public function draw(renderer:Renderer):void
		{
			if(visible)
			{
				renderer.draw(_imageFile, _animIndex, _animFrame, x, y);
			}
		}
		
		public function willTrigger(type:String):Boolean
		{
			return _dispatcher.willTrigger(type);
		}
		
		public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
		{
			_dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
		}
		
		public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
		{
			_dispatcher.removeEventListener(type, listener, useCapture);
		}
		
		public function dispatchEvent(e:Event):Boolean
		{
			return _dispatcher.dispatchEvent(e);
		}
		
		public function hasEventListener(type:String):Boolean
		{
			return _dispatcher.hasEventListener(type);
		}
	}
}